<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib prefix="sitemesh"
	uri="http://www.opensymphony.com/sitemesh/decorator"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="decorator" content="mainframe" />
<title>角色管理</title>
</head>
<body>
	<!-- Content Header (Page header) -->
	<section class="content-header">
		<h1>
			角色<small>列表显示</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="#"><i class="fa fa-dashboard"></i>角色管理</a></li>
			<!-- <li class="active">Here</li> -->
		</ol>
	</section>
	<!-- Main content -->
	<section class="content">
		<div class="box  box-default">
			<div class="box-header">
				<button type="button" class="btn btn-default" id="add">添加</button>
				<div class="box-tools pull-right" >
				<form class="form-horizontal" role="form" id="searchForm" action="<%=request.getContextPath()%>/role/list">
					<input type="hidden" name="totalPages" id="totalPages" value="${pager.totalPages }"/>
					<input type="hidden" name="pageNo" id="pageNo" value="${pager.pageNo }"/>
					<input type="hidden" name="pageSize" value="${pager.pageSize }"/>
				</form>
				</div>
			</div>

			<div class="box-body">
				<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
					<input type="hidden" value="${message}" id="message">
					<!--<caption>基本的表格布局</caption>  -->
					<thead>
						<tr>
						  <th>角色名称</th>
						  <th>描述</th>
						  <th>状态</th>
						  <th>创建时间</th>
						  <th>更新时间</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach var="role" items="${pager.datas}" varStatus="status">
							<tr>
							     
								<input type="hidden" id="pk${status.index }" name="roleId" value="${role.roleId}"/>
								<td>${role.name}</td>
								<td>${role.description}</td>
								<td>
									<c:if test="${role.status  eq 1}"><span style="color:green">激活</span></c:if>
									<c:if test="${role.status  eq 2}"><span style="color:red">禁用</span></c:if></td>
								</td>
								<td><fmt:formatDate value="${role.createTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								<td><fmt:formatDate value="${role.updateTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								<td><a href="javascript:void(0)"
									onclick='updateOne(this)' style="cursor: pointer;">修改</a> <a
									href="javascript:void(0)" onclick='deleteOne(this);'
									style="cursor: pointer;">删除</a></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				<nav id="pager"></nav>
			</div>
		</div>

	</section>
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/static/plugins/jquery/pager/jquery.pager.bootstrap.js"></script>
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/static/plugins/jquery/pager/pager.js"></script>
	<script>
		var path = "<%=request.getContextPath()%>";
		//传递的参数
		var totalPages ="${pager.totalPages}";	
		var pageNo ="${pager.pageNo}";	
		var pageSize ="${pager.pageSize}";
		
		$(document).ready(function() {
			//操作成功提示
			  var message=  $('#message').val();
			  if(message!=null&&message!=''){
				  alert(message);
			  }
			initPager("pager", pageNo, totalPages, function(pageclickednumber){
				$("input[name='pageNo']").val(pageclickednumber);
				$("#searchForm").submit();
		 	}, {});
			$("#add").bind("click", function() {
				window.location.href=path+"/role/addUI";
	         });
		});
		
		function submitSearch(){
			$("#searchForm").submit();
 	 	}
		
		function deleteOne(nowTr){
			confirmBox("确定删除?", function(nowTr){
				var roleId= $(nowTr).parent().parent().find("input[name=roleId]").val();
				 $.ajax({
					 url:path+"/delete/"+roleId,
					 data: {roleId:roleId},
		             dataType: "json",
					 success:function(msg){
							if(msg>0){
								alert("删除成功");
								$(nowTr).parent().parent().remove();
							}else{
								alert("删除失败");
							}
					}
				});			
			}, nowTr, {
				cancleText : "再想想", 
				okText :  "删除",
			});
		};
		function updateOne(nowTr){
			var roleId = $(nowTr).parent().parent().find("input[name=roleId]").val();
			window.location.href=path+"/user/updateUI/"+roleId;
		};
	</script>
</body>
</html>